`
https://leetcode.cn/problems/maximum-points-inside-the-square/
`

/**
 * @param {number[][]} points
 * @param {string} s
 * @return {number}
 */
var maxPointsInsideSquare = function (points, s) {
  let res;
  const check = (size) => {
    // 用位运算存储
    let vis = 0
    for (let i = 0; i < points.length; i++) {
      // 判断点是否在正方形中
      if (Math.abs(points[i][0]) <= size && Math.abs(points[i][1]) <= size) {
        const c = s.charCodeAt(i) - 'a'.charCodeAt(0)
        // c 在集合中
        if ((vis >> c & 1) > 0) {
          return false
        }
        vis |= 1 << c // 把 c 加入集合
      }
    }
    // 计算 vis 的二进制有多少个 1
    res = (vis.toString(2).match(/1/g) || []).length
    return true
  }

  let left = -1, right = 1e9 + 1
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (check(mid)) {
      left = mid
    } else {
      right = mid
    }
  }

  return res
};